import * as Cesium from 'cesium';


//初始化 cesium
export function init_cesium() {

    //自适应 网页全屏
    const cesiumContainer = document.getElementById('cesiumContainer');
    if (cesiumContainer) {
    cesiumContainer.style.position = 'absolute';
    cesiumContainer.style.top = '0';
    cesiumContainer.style.left = '0';
    cesiumContainer.style.width = '100vw';
    cesiumContainer.style.height = '100vh';
    cesiumContainer.style.zIndex = '-999';
    }

    //let viewer = new Cesium.Viewer("cesiumContainer",)
    let viewer = new Cesium.Viewer("cesiumContainer", {
        //搜索框
        geocoder: false,
        //home键
        homeButton: false,
        // 动画控件
        animation: false,
        //全屏按钮
        fullscreenButton: false,
        //场景模式选择器
        sceneModePicker: false,
        //时间轴
        timeline: false,
        //导航提示
        navigationHelpButton: false,
        //地图选择器
        baseLayerPicker: false,
 
      
    })

    const creditsElement = document.querySelector('.cesium-viewer-bottom') as HTMLElement;
    if (creditsElement) {
    creditsElement.style.display = 'none';
    } 

    // viewer.imageryLayers.addImageryProvider(new Cesium.UrlTemplateImageryProvider({
    //     url: "http://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",
    //     minimumLevel: 1,
    //     maximumLevel: 18
    //   }));

    var imaglyser = new Cesium.ImageryLayer(new Cesium.UrlTemplateImageryProvider({
        url: " http://webst01.is.autonavi.com/appmaptile?style=8&x={x}&y={y}&z={z}",
        minimumLevel: 1,
        maximumLevel: 18
    }));

    //在添加 层 指定的瓦片
    viewer.imageryLayers.add(imaglyser); 

    //相机飞跃到 指定 坐标
    viewer.camera.flyTo({ 
        destination: Cesium.Cartesian3.fromDegrees(109, 34, 1000000),
        orientation: {
            heading: Cesium.Math.toRadians(0), // 水平偏角，默认正北 0
            pitch: Cesium.Math.toRadians(-90), // 俯视角，默认-90，垂直向下
            roll: 0, // 旋转角
        },
        duration: 5
    });

    console.log(viewer, 777)
}

